package algorithm_optimal_solution.StackAndQueue;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;

public class StackForAnotherStackSort {

    public static Stack<Integer> sortStack(Stack<Integer> stack){
        Stack<Integer> helpStack = new Stack<>();
        while(!stack.isEmpty()){
            Integer number = stack.pop();
            while(!helpStack.isEmpty() && helpStack.peek() > number){
                stack.push(helpStack.pop());
            }
            helpStack.push(number);
        }
        return helpStack;
    }

    public static void main(String[] args)throws IOException {
        BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
        int len = Integer.parseInt(scanner.readLine());
        String value=scanner.readLine();
        String[] result = value.split(" ");
        Stack<Integer> stack = new Stack<>();
        for(int i=0;i<len;i++){
            stack.push(Integer.parseInt(result[i]));
        }
        Stack<Integer> helpStack = sortStack(stack);
        for(int i=0;i<len;i++){
            System.out.printf("%s ",helpStack.pop());
        }
    }
}
